package handlers;


import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

import common.classes.HeaderWorker;


public class ErrorHandler extends Handler {
	
	public ErrorHandler() {
		super();
	}
	
	public ErrorHandler(Handler next) {
		super(next);
	}
	
	@Override
	public void parseRequest(Socket socket, HeaderWorker header, String error) {
		try {
			OutputStream os = socket.getOutputStream();
			os.write(("HTTP\\1.1" + error +  "\r\nContent-type: text/html\r\n\r\n").getBytes());
			os.write(("<canter><h1>ERROR: " + error + "<h1></center>").getBytes());
			os.flush();
			os.close();
		} catch(IOException e) {
			System.err.println(e);
		} finally {
			this.closeSocket(socket);
		}
	}
}
